﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Base.cshtml";
    var curuser = System.Web.HttpContext.Current.User.Identity.Name;
}
@section head{
    <script src="/Content/roohui/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
    <script src="/Content/roohui/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
    <script src="/Content/roohui/jquery-validation/messages_cn.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#txtKey").ligerTextBox({ width: 250 });
            $("#guaranteeCompany").ligerComboBox(
            {
                url: '/GuarCompany/GetGuarCompanyListByKey',
                valueField: 'ID',
                textField: 'CompanyName',
                autocomplete: true,
                width: 180
            });
            $("#product").ligerComboBox(
            {
                url: '/Product/GetProductListByKey',
                valueField: 'ID',
                textField: 'ProductName',
                autocomplete: true,
                width: 180
            });
            $("#txtKey").focus();

            liger.get("guaranteeCompany").setValue("-1");
            liger.get("product").setValue("-1");
        });

    </script>
}
<div id="toptoolbar" style="width: 100%">
</div>
<table cellpadding="0" cellspacing="0" class="l-table-edit">
    <tr>
        <td align="right" class="l-table-edit-td">
            关键字:
        </td>
        <td align="left" class="l-table-edit-td">
            <input id="txtKey" ltype="text" ligerui="width:250" style="width: 250;"/>
        </td>
        <td align="right" class="l-table-edit-td">
            产品名称:
        </td>
        <td align="left" class="l-table-edit-td">
            <input id="product" ltype="text" ligerui="width:180" style="width:180;"/>
        </td>
        <td align="right" class="l-table-edit-td">
            担保公司:
        </td>
        <td align="left" class="l-table-edit-td">
            <input id="guaranteeCompany" ltype="text" ligerui="width:180" style="width:180;"/>
        </td>
        <td align="right" class="l-table-edit-td">
            状态:
        </td>
        <td align="left" class="l-table-edit-td">
            <select id="selStatus" ltype="select" ligerui="width:150" style="width:150;">
                <option id="-2" value="全部">全部</option>
                <option id="-1" value="审核不通过">审核不通过</option>
                <option id="0" value="保存">保存</option>
                <option id="1" value="提交">提交</option>
                <option id="2" value="审核中">审核中</option>
                <option id="3" value="审核通过">审核通过</option>
                <option id="4" value="已发布">已发布</option>
                <option id="5" value="流标">流标</option>
                <option id="6" value="满标">满标</option>
                <option id="7" value="融资成功">融资成功</option>
                <option id="8" value="还款中">还款中</option>
                <option id="9" value="完毕">完毕</option>
            </select>
        </td>
        <td align="left" class="l-table-edit-td">
            <input type="button" value="查询" id="btnSearch" onclick="search()" class="l-button" />
        </td>
    </tr>
</table>
<div id="projectgrid">
</div>
<script type="text/javascript">
    var projectgrid;
    $(function () {
        $("#toptoolbar").ligerToolBar({ items: [
            { text: '新增', click: grid_project_add, icon: "add" },
            { text: '刷新', click: grid_project_refresh, icon: "refresh" }
            ]
        });
        projectgrid = $("#projectgrid").ligerGrid({
            columns: [
                { display: '项目编码', name: 'ProjectCode', width: '8%', isSort: false },
                { display: '项目名称', name: 'ProjectTitle', width: '15%', isSort: false },
                { display: '产品名称', name: 'ProductName', width: '15%', isSort: false },
                { display: '借款企业', name: 'EnterpriseName', width: '15%', isSort: false,
                    render: function (item) {
                        return item.Enterprise.EnterpriseName;
                    }
                },
                { display: '借款金额', name: 'Amount', width: '8%', isSort: false,
                    render: function (item) {
                        return Number(item.Financing / 10000).toFixed(2) + "万元";
                    }
                },
                { display: '借款时长', name: 'Duration', width: '8%', isSort: false,
                    render: function (item) {
                        var durationType = item.Policy.DurationType == 0 ? "天" : "月";
                        return (item.CycleAmount * item.Policy.Duration) + durationType;
                    }
                },
                { display: '担保公司', name: 'CompanyName', width: '10%', isSort: false,
                    render: function (item) {
                        return item.GuaranteeCompany.CompanyName;
                    }
                },

                { display: '状态', name: 'Status', width: '6%', isSort: false,
                    render: function (item) {
                        if (parseInt(item.Status) == -1) return '审核不通过';
                        else if (parseInt(item.Status) == 0) return '保存';
                        else if (parseInt(item.Status) == 1) return '提交';
                        else if (parseInt(item.Status) == 2) return '审核中';
                        else if (parseInt(item.Status) == 3) return '审核通过';
                        else if (parseInt(item.Status) == 4) return '已发布';
                        else if (parseInt(item.Status) == 5) return '流标';
                        else if (parseInt(item.Status) == 6) return '满标';
                        else if (parseInt(item.Status) == 7) return '融资成功';
                        else if (parseInt(item.Status) == 8) return '还款中';
                        else if (parseInt(item.Status) == 9) return '完毕';
                    }
                },
                {
                    display: '操作', isAllowHide: false,
                    render: function (row) {
                        var html = '<a href="#" onclick="projectShow(\'' + row.ID + '\', 2)">详情</a>';
                        if (row.CreateUser == '@curuser') {
                            if (row.Status == 0) {
                                html = html + '&nbsp;&nbsp;<a href="#" onclick="projectShow(\'' + row.ID + '\', 1)">修改</a>';
                                html = html + '&nbsp;&nbsp;<a href="#" onclick="changeProjectStatus(\'' + row.ID + '\',1)">提交</a>';
                                html = html + '&nbsp;&nbsp;<a href="#" onclick="changeProjectStatus(\'' + row.ID + '\',99)">删除</a>';
                            }
                        }
                        return html;
                    }
                }
                ],
            width: '100%', height: '100%', rownumbers: true,
            dataAction: 'server',
            url: "/Project/GetProjectListByPage",
            pageSizeOptions: [20],
            pageSize: 20
        });

    });

    function grid_project_add() {
        location.href = decodeURIComponent("/Project/ProjectAdd");
    }

    function search() {
        var guaranteeCompanyID = liger.get("guaranteeCompany").getValue();
        if (guaranteeCompanyID == "") {
            guaranteeCompanyID = "-1";
        }
        var productID = liger.get("product").getValue();
        if (productID == "") {
            productID = "-1";
        }
        var statusID = liger.get("selStatus").getValue();
        if (statusID == "") {
            statusID = "-2";
        }
        projectgrid.setOptions(
             {
                 parms:
                [
                    { name: "key", value: $("#txtKey").val() },
                    { name: "guaranteeCompanyID", value: guaranteeCompanyID },
                    { name: "productID", value: productID },
                    { name: "status", value: statusID },
                    { name: "page", value: 1 }
                ]
             });
        projectgrid.loadData();
    }

    // 修改或详情展示
    function projectShow(projectID, opertype) {
        if (opertype == 1) {
            location.href = decodeURIComponent("/Project/ProjectEdit?projectId=" + projectID);
        }
        else if (opertype == 2) {
            location.href = decodeURIComponent("/Project/ProjectDetails?projectId=" + projectID);
        }
    }

    // 提交
    function changeProjectStatus(projectID, destinatstatus) {
        var operate;
        if (destinatstatus == 1) {
            operate = "提交";
        }
        else if (destinatstatus == 99) {
            operate = "删除";
        }
        $.ligerDialog.confirm('确定要【' + operate + '】该项目吗？', '温馨提示', function (result) {
            if (result) {
                $.ajax({
                    url: '/Project/ProjectStatusChange',
                    data: "projectId=" + projectID + "&destinatStatus=" + destinatstatus,
                    type: "post",
                    success: function (result) {
                        if (result == "OK") {
                            $.ligerDialog.success(operate + '成功！');
                            grid_project_refresh();
                        } else {
                            $.ligerDialog.error(ooperate + '失败！', '温馨提示');
                        }
                    }
                });
            }
        });
    }
    // 刷新
    function grid_project_refresh() {
        projectgrid.setOptions(
             {
                 parms:
                [
                    { name: "page", value: 1 }
                ]
             });
             projectgrid.loadData();
    }

</script>
